﻿<UserControl x:Class="Workbench.Presentation.POSTypesTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vm="clr-namespace:Workbench.Presentation"
             mc:Ignorable="d" 
             DataContextChanged="UserControl_DataContextChanged"
             d:DesignHeight="300" d:DesignWidth="300">
    <DockPanel>
        <Border BorderBrush="Black" 
                BorderThickness="0 0 0 0.25" 
                DockPanel.Dock="Top">
            <TextBlock DockPanel.Dock="Top" FontSize="18" Padding="0 5">Part-of-speech Types</TextBlock>
        </Border>

        <Border Margin="0 10 0 0" 
                 BorderBrush="Black" BorderThickness="0.7">
            <TreeView DockPanel.Dock="Top" BorderThickness="0"
                  ItemsSource="{Binding Path=POSTypes}"
                  FontSize="13"
                  PreviewMouseRightButtonDown="TreeView_PreviewMouseRightButtonDown">
                <TreeView.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Add Part-of-speech type" Click="AddPOSType_Click"></MenuItem>
                    </ContextMenu>
                </TreeView.ContextMenu>
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                        <Setter Property="FontWeight" Value="Normal"></Setter>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="FontWeight" Value="Bold"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TreeView.ItemContainerStyle>
                <TreeView.Resources>
                    <Style TargetType="{x:Type Image}">
                        <Setter Property="Width" Value="16"></Setter>
                        <Setter Property="Height" Value="16"></Setter>
                    </Style>

                    <HierarchicalDataTemplate DataType="{x:Type vm:POSTypeViewModel}" ItemsSource="{Binding Children}">
                        <Grid Margin="3 0" Tag="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}">
                            <Grid.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Add Subtype" Click="Addsubtype_Click"></MenuItem>
                                    <MenuItem Header="Remove Type" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}" />
                                    <Separator/>
                                    <MenuItem Header="Rename"></MenuItem>
                                </ContextMenu>
                            </Grid.ContextMenu>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" MinWidth="250" SharedSizeGroup="col1"></ColumnDefinition>
                                <ColumnDefinition Width="Auto" SharedSizeGroup="col2"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" HorizontalAlignment="Left" Text="{Binding Name}" />
                            <TextBlock Grid.Column="1" HorizontalAlignment="Right" Text="{Binding Count}" />
                        </Grid>
                    </HierarchicalDataTemplate>
                </TreeView.Resources>
            </TreeView>
        </Border>
    </DockPanel>
</UserControl>
